1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19 
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 
25 module adw.Leaflet;
26 
27 private import adw.LeafletPage;
28 private import adw.SpringParams;
29 private import adw.SwipeableIF;
30 private import adw.SwipeableT;
31 private import adw.c.functions;
32 public  import adw.c.types;
33 private import glib.ConstructionException;
34 private import glib.Str;
35 private import glib.c.functions;
36 private import gobject.ObjectG;
37 private import gtk.AccessibleIF;
38 private import gtk.AccessibleT;
39 private import gtk.BuildableIF;
40 private import gtk.BuildableT;
41 private import gtk.ConstraintTargetIF;
42 private import gtk.ConstraintTargetT;
43 private import gtk.OrientableIF;
44 private import gtk.OrientableT;
45 private import gtk.SelectionModelIF;
46 private import gtk.Widget;
47 
48 
49 /**
50  * An adaptive container acting like a box or a stack.
51  * 
52  * <picture>
53  * <source srcset="leaflet-wide-dark.png" media="(prefers-color-scheme: dark)">
54  * <img src="leaflet-wide.png" alt="leaflet-wide">
55  * </picture>
56  * <picture>
57  * <source srcset="leaflet-narrow-dark.png" media="(prefers-color-scheme: dark)">
58  * <img src="leaflet-narrow.png" alt="leaflet-narrow">
59  * </picture>
60  * 
61  * The `AdwLeaflet` widget can display its children like a [class@Gtk.Box] does
62  * or like a [class@Gtk.Stack] does, adapting to size changes by switching
63  * between the two modes.
64  * 
65  * When there is enough space the children are displayed side by side, otherwise
66  * only one is displayed and the leaflet is said to be “folded”.
67  * The threshold is dictated by the preferred minimum sizes of the children.
68  * When a leaflet is folded, the children can be navigated using swipe gestures.
69  * 
70  * The “over” and “under” transition types stack the children one on top of the
71  * other, while the “slide” transition puts the children side by side. While
72  * navigating to a child on the side or below can be performed by swiping the
73  * current child away, navigating to an upper child requires dragging it from
74  * the edge where it resides. This doesn't affect non-dragging swipes.
75  * 
76  * ## CSS nodes
77  * 
78  * `AdwLeaflet` has a single CSS node with name `leaflet`. The node will get the
79  * style classes `.folded` when it is folded, `.unfolded` when it's not, or none
80  * if it hasn't computed its fold yet.
81  *
82  * Since: 1.0
83  */
84 public class Leaflet : Widget, SwipeableIF, OrientableIF
85 {
86 	/** the main Gtk struct */
87 	protected AdwLeaflet* adwLeaflet;
88 
89 	/** Get the main Gtk struct */
90 	public AdwLeaflet* getLeafletStruct(bool transferOwnership = false)
91 	{
92 		if (transferOwnership)
93 			ownedRef = false;
94 		return adwLeaflet;
95 	}
96 
97 	/** the main Gtk struct as a void* */
98 	protected override void* getStruct()
99 	{
100 		return cast(void*)adwLeaflet;
101 	}
102 
103 	/**
104 	 * Sets our main struct and passes it to the parent class.
105 	 */
106 	public this (AdwLeaflet* adwLeaflet, bool ownedRef = false)
107 	{
108 		this.adwLeaflet = adwLeaflet;
109 		super(cast(GtkWidget*)adwLeaflet, ownedRef);
110 	}
111 
112 	// add the Swipeable capabilities
113 	mixin SwipeableT!(AdwLeaflet);
114 
115 	// add the Orientable capabilities
116 	mixin OrientableT!(AdwLeaflet);
117 
118 
119 	/** */
120 	public static GType getType()
121 	{
122 		return adw_leaflet_get_type();
123 	}
124 
125 	/**
126 	 * Creates a new `AdwLeaflet`.
127 	 *
128 	 * Returns: the new created `AdwLeaflet`
129 	 *
130 	 * Since: 1.0
131 	 *
132 	 * Throws: ConstructionException GTK+ fails to create the object.
133 	 */
134 	public this()
135 	{
136 		auto __p = adw_leaflet_new();
137 
138 		if(__p is null)
139 		{
140 			throw new ConstructionException("null returned by new");
141 		}
142 
143 		this(cast(AdwLeaflet*) __p);
144 	}
145 
146 	/**
147 	 * Adds a child to @self.
148 	 *
149 	 * Params:
150 	 *     child = the widget to add
151 	 *
152 	 * Returns: the [class@LeafletPage] for @child
153 	 *
154 	 * Since: 1.0
155 	 */
156 	public LeafletPage append(Widget child)
157 	{
158 		auto __p = adw_leaflet_append(adwLeaflet, (child is null) ? null : child.getWidgetStruct());
159 
160 		if(__p is null)
161 		{
162 			return null;
163 		}
164 
165 		return ObjectG.getDObject!(LeafletPage)(cast(AdwLeafletPage*) __p);
166 	}
167 
168 	/**
169 	 * Finds the previous or next navigatable child.
170 	 *
171 	 * This will be the same child [method@Leaflet.navigate] or swipe gestures will
172 	 * navigate to.
173 	 *
174 	 * If there's no child to navigate to, `NULL` will be returned instead.
175 	 *
176 	 * See [property@LeafletPage:navigatable].
177 	 *
178 	 * Params:
179 	 *     direction = the direction
180 	 *
181 	 * Returns: the previous or next child
182 	 *
183 	 * Since: 1.0
184 	 */
185 	public Widget getAdjacentChild(AdwNavigationDirection direction)
186 	{
187 		auto __p = adw_leaflet_get_adjacent_child(adwLeaflet, direction);
188 
189 		if(__p is null)
190 		{
191 			return null;
192 		}
193 
194 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
195 	}
196 
197 	/**
198 	 * Gets whether gestures and shortcuts for navigating backward are enabled.
199 	 *
200 	 * Returns: Whether gestures and shortcuts are enabled.
201 	 *
202 	 * Since: 1.0
203 	 */
204 	public bool getCanNavigateBack()
205 	{
206 		return adw_leaflet_get_can_navigate_back(adwLeaflet) != 0;
207 	}
208 
209 	/**
210 	 * Gets whether gestures and shortcuts for navigating forward are enabled.
211 	 *
212 	 * Returns: Whether gestures and shortcuts are enabled.
213 	 *
214 	 * Since: 1.0
215 	 */
216 	public bool getCanNavigateForward()
217 	{
218 		return adw_leaflet_get_can_navigate_forward(adwLeaflet) != 0;
219 	}
220 
221 	/**
222 	 * Gets whether @self can unfold.
223 	 *
224 	 * Returns: whether @self can unfold
225 	 *
226 	 * Since: 1.0
227 	 */
228 	public bool getCanUnfold()
229 	{
230 		return adw_leaflet_get_can_unfold(adwLeaflet) != 0;
231 	}
232 
233 	/**
234 	 * Finds the child of @self with @name.
235 	 *
236 	 * Returns `NULL` if there is no child with this name.
237 	 *
238 	 * See [property@LeafletPage:name].
239 	 *
240 	 * Params:
241 	 *     name = the name of the child to find
242 	 *
243 	 * Returns: the requested child of @self
244 	 *
245 	 * Since: 1.0
246 	 */
247 	public Widget getChildByName(string name)
248 	{
249 		auto __p = adw_leaflet_get_child_by_name(adwLeaflet, Str.toStringz(name));
250 
251 		if(__p is null)
252 		{
253 			return null;
254 		}
255 
256 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
257 	}
258 
259 	/**
260 	 * Gets the child transition spring parameters for @self.
261 	 *
262 	 * Returns: the child transition parameters
263 	 *
264 	 * Since: 1.0
265 	 */
266 	public SpringParams getChildTransitionParams()
267 	{
268 		auto __p = adw_leaflet_get_child_transition_params(adwLeaflet);
269 
270 		if(__p is null)
271 		{
272 			return null;
273 		}
274 
275 		return ObjectG.getDObject!(SpringParams)(cast(AdwSpringParams*) __p, true);
276 	}
277 
278 	/**
279 	 * Gets whether a child transition is currently running for @self.
280 	 *
281 	 * Returns: whether a transition is currently running
282 	 *
283 	 * Since: 1.0
284 	 */
285 	public bool getChildTransitionRunning()
286 	{
287 		return adw_leaflet_get_child_transition_running(adwLeaflet) != 0;
288 	}
289 
290 	/**
291 	 * Gets the fold threshold policy for @self.
292 	 *
293 	 * Since: 1.0
294 	 */
295 	public AdwFoldThresholdPolicy getFoldThresholdPolicy()
296 	{
297 		return adw_leaflet_get_fold_threshold_policy(adwLeaflet);
298 	}
299 
300 	/**
301 	 * Gets whether @self is folded.
302 	 *
303 	 * Returns: whether @self is folded.
304 	 *
305 	 * Since: 1.0
306 	 */
307 	public bool getFolded()
308 	{
309 		return adw_leaflet_get_folded(adwLeaflet) != 0;
310 	}
311 
312 	/**
313 	 * Gets whether @self is homogeneous.
314 	 *
315 	 * Returns: whether @self is homogeneous
316 	 *
317 	 * Since: 1.0
318 	 */
319 	public bool getHomogeneous()
320 	{
321 		return adw_leaflet_get_homogeneous(adwLeaflet) != 0;
322 	}
323 
324 	/**
325 	 * Gets the mode transition animation duration for @self.
326 	 *
327 	 * Returns: the mode transition duration, in milliseconds.
328 	 *
329 	 * Since: 1.0
330 	 */
331 	public uint getModeTransitionDuration()
332 	{
333 		return adw_leaflet_get_mode_transition_duration(adwLeaflet);
334 	}
335 
336 	/**
337 	 * Returns the [class@LeafletPage] object for @child.
338 	 *
339 	 * Params:
340 	 *     child = a child of @self
341 	 *
342 	 * Returns: the page object for @child
343 	 *
344 	 * Since: 1.0
345 	 */
346 	public LeafletPage getPage(Widget child)
347 	{
348 		auto __p = adw_leaflet_get_page(adwLeaflet, (child is null) ? null : child.getWidgetStruct());
349 
350 		if(__p is null)
351 		{
352 			return null;
353 		}
354 
355 		return ObjectG.getDObject!(LeafletPage)(cast(AdwLeafletPage*) __p);
356 	}
357 
358 	/**
359 	 * Returns a [iface@Gio.ListModel] that contains the pages of the leaflet.
360 	 *
361 	 * This can be used to keep an up-to-date view. The model also implements
362 	 * [iface@Gtk.SelectionModel] and can be used to track and change the visible
363 	 * page.
364 	 *
365 	 * Returns: a `GtkSelectionModel` for the leaflet's children
366 	 *
367 	 * Since: 1.0
368 	 */
369 	public SelectionModelIF getPages()
370 	{
371 		auto __p = adw_leaflet_get_pages(adwLeaflet);
372 
373 		if(__p is null)
374 		{
375 			return null;
376 		}
377 
378 		return ObjectG.getDObject!(SelectionModelIF)(cast(GtkSelectionModel*) __p, true);
379 	}
380 
381 	/**
382 	 * Gets the type of animation used for transitions between modes and children.
383 	 *
384 	 * Returns: the current transition type of @self
385 	 *
386 	 * Since: 1.0
387 	 */
388 	public AdwLeafletTransitionType getTransitionType()
389 	{
390 		return adw_leaflet_get_transition_type(adwLeaflet);
391 	}
392 
393 	/**
394 	 * Gets the widget currently visible when the leaflet is folded.
395 	 *
396 	 * Returns: the visible child
397 	 *
398 	 * Since: 1.0
399 	 */
400 	public Widget getVisibleChild()
401 	{
402 		auto __p = adw_leaflet_get_visible_child(adwLeaflet);
403 
404 		if(__p is null)
405 		{
406 			return null;
407 		}
408 
409 		return ObjectG.getDObject!(Widget)(cast(GtkWidget*) __p);
410 	}
411 
412 	/**
413 	 * Gets the name of the currently visible child widget.
414 	 *
415 	 * Returns: the name of the visible child
416 	 *
417 	 * Since: 1.0
418 	 */
419 	public string getVisibleChildName()
420 	{
421 		return Str.toString(adw_leaflet_get_visible_child_name(adwLeaflet));
422 	}
423 
424 	/**
425 	 * Inserts @child in the position after @sibling in the list of children.
426 	 *
427 	 * If @sibling is `NULL`, inserts @child at the first position.
428 	 *
429 	 * Params:
430 	 *     child = the widget to insert
431 	 *     sibling = the sibling after which to insert @child
432 	 *
433 	 * Returns: the [class@LeafletPage] for @child
434 	 *
435 	 * Since: 1.0
436 	 */
437 	public LeafletPage insertChildAfter(Widget child, Widget sibling)
438 	{
439 		auto __p = adw_leaflet_insert_child_after(adwLeaflet, (child is null) ? null : child.getWidgetStruct(), (sibling is null) ? null : sibling.getWidgetStruct());
440 
441 		if(__p is null)
442 		{
443 			return null;
444 		}
445 
446 		return ObjectG.getDObject!(LeafletPage)(cast(AdwLeafletPage*) __p);
447 	}
448 
449 	/**
450 	 * Navigates to the previous or next child.
451 	 *
452 	 * The child must have the [property@LeafletPage:navigatable] property set to
453 	 * `TRUE`, otherwise it will be skipped.
454 	 *
455 	 * This will be the same child as returned by
456 	 * [method@Leaflet.get_adjacent_child] or navigated to via swipe gestures.
457 	 *
458 	 * Params:
459 	 *     direction = the direction
460 	 *
461 	 * Returns: whether the visible child was changed
462 	 *
463 	 * Since: 1.0
464 	 */
465 	public bool navigate(AdwNavigationDirection direction)
466 	{
467 		return adw_leaflet_navigate(adwLeaflet, direction) != 0;
468 	}
469 
470 	/**
471 	 * Inserts @child at the first position in @self.
472 	 *
473 	 * Params:
474 	 *     child = the widget to prepend
475 	 *
476 	 * Returns: the [class@LeafletPage] for @child
477 	 *
478 	 * Since: 1.0
479 	 */
480 	public LeafletPage prepend(Widget child)
481 	{
482 		auto __p = adw_leaflet_prepend(adwLeaflet, (child is null) ? null : child.getWidgetStruct());
483 
484 		if(__p is null)
485 		{
486 			return null;
487 		}
488 
489 		return ObjectG.getDObject!(LeafletPage)(cast(AdwLeafletPage*) __p);
490 	}
491 
492 	/**
493 	 * Removes a child widget from @self.
494 	 *
495 	 * Params:
496 	 *     child = the child to remove
497 	 *
498 	 * Since: 1.0
499 	 */
500 	public void remove(Widget child)
501 	{
502 		adw_leaflet_remove(adwLeaflet, (child is null) ? null : child.getWidgetStruct());
503 	}
504 
505 	/**
506 	 * Moves @child to the position after @sibling in the list of children.
507 	 *
508 	 * If @sibling is `NULL`, moves @child to the first position.
509 	 *
510 	 * Params:
511 	 *     child = the widget to move, must be a child of @self
512 	 *     sibling = the sibling to move @child after
513 	 *
514 	 * Since: 1.0
515 	 */
516 	public void reorderChildAfter(Widget child, Widget sibling)
517 	{
518 		adw_leaflet_reorder_child_after(adwLeaflet, (child is null) ? null : child.getWidgetStruct(), (sibling is null) ? null : sibling.getWidgetStruct());
519 	}
520 
521 	/**
522 	 * Sets whether gestures and shortcuts for navigating backward are enabled.
523 	 *
524 	 * Params:
525 	 *     canNavigateBack = the new value
526 	 *
527 	 * Since: 1.0
528 	 */
529 	public void setCanNavigateBack(bool canNavigateBack)
530 	{
531 		adw_leaflet_set_can_navigate_back(adwLeaflet, canNavigateBack);
532 	}
533 
534 	/**
535 	 * Sets whether gestures and shortcuts for navigating forward are enabled.
536 	 *
537 	 * Params:
538 	 *     canNavigateForward = the new value
539 	 *
540 	 * Since: 1.0
541 	 */
542 	public void setCanNavigateForward(bool canNavigateForward)
543 	{
544 		adw_leaflet_set_can_navigate_forward(adwLeaflet, canNavigateForward);
545 	}
546 
547 	/**
548 	 * Sets whether @self can unfold.
549 	 *
550 	 * Params:
551 	 *     canUnfold = whether @self can unfold
552 	 *
553 	 * Since: 1.0
554 	 */
555 	public void setCanUnfold(bool canUnfold)
556 	{
557 		adw_leaflet_set_can_unfold(adwLeaflet, canUnfold);
558 	}
559 
560 	/**
561 	 * Sets the child transition spring parameters for @self.
562 	 *
563 	 * Params:
564 	 *     params = the new parameters
565 	 *
566 	 * Since: 1.0
567 	 */
568 	public void setChildTransitionParams(SpringParams params)
569 	{
570 		adw_leaflet_set_child_transition_params(adwLeaflet, (params is null) ? null : params.getSpringParamsStruct());
571 	}
572 
573 	/**
574 	 * Sets the fold threshold policy for @self.
575 	 *
576 	 * Params:
577 	 *     policy = the policy to use
578 	 *
579 	 * Since: 1.0
580 	 */
581 	public void setFoldThresholdPolicy(AdwFoldThresholdPolicy policy)
582 	{
583 		adw_leaflet_set_fold_threshold_policy(adwLeaflet, policy);
584 	}
585 
586 	/**
587 	 * Sets @self to be homogeneous or not.
588 	 *
589 	 * If set to `FALSE`, different children can have different size along the
590 	 * opposite orientation.
591 	 *
592 	 * Params:
593 	 *     homogeneous = whether to make @self homogeneous
594 	 *
595 	 * Since: 1.0
596 	 */
597 	public void setHomogeneous(bool homogeneous)
598 	{
599 		adw_leaflet_set_homogeneous(adwLeaflet, homogeneous);
600 	}
601 
602 	/**
603 	 * Sets the mode transition animation duration for @self.
604 	 *
605 	 * Params:
606 	 *     duration = the new duration, in milliseconds
607 	 *
608 	 * Since: 1.0
609 	 */
610 	public void setModeTransitionDuration(uint duration)
611 	{
612 		adw_leaflet_set_mode_transition_duration(adwLeaflet, duration);
613 	}
614 
615 	/**
616 	 * Sets the type of animation used for transitions between modes and children.
617 	 *
618 	 * Params:
619 	 *     transition = the new transition type
620 	 *
621 	 * Since: 1.0
622 	 */
623 	public void setTransitionType(AdwLeafletTransitionType transition)
624 	{
625 		adw_leaflet_set_transition_type(adwLeaflet, transition);
626 	}
627 
628 	/**
629 	 * Sets the widget currently visible when the leaflet is folded.
630 	 *
631 	 * Params:
632 	 *     visibleChild = the new child
633 	 *
634 	 * Since: 1.0
635 	 */
636 	public void setVisibleChild(Widget visibleChild)
637 	{
638 		adw_leaflet_set_visible_child(adwLeaflet, (visibleChild is null) ? null : visibleChild.getWidgetStruct());
639 	}
640 
641 	/**
642 	 * Makes the child with the name @name visible.
643 	 *
644 	 * See adw_leaflet_set_visible_child() for more details.
645 	 *
646 	 * Params:
647 	 *     name = the name of a child
648 	 *
649 	 * Since: 1.0
650 	 */
651 	public void setVisibleChildName(string name)
652 	{
653 		adw_leaflet_set_visible_child_name(adwLeaflet, Str.toStringz(name));
654 	}
655 }